/**
* Created by yyr on 2018/1/10
*已设立基金》基本信息详情
*/
<template>
    <div>
        <div class="ca-box-border-top-none ca-p-22" v-if="!isBasicEdit">
            <el-row>
                <el-col :span="12" class="ca-title">
                    <h3>基本信息</h3>
                </el-col>
                <el-col :span='12' class="ca-align-right">
                    <el-button type="text"  @click="fundBasicEdit()" :disabled="!isAuthBasicEdit" class="ca-edit-btn el-icon-edit">编辑</el-button>
                </el-col>
            </el-row>
            <div>
                <el-form label-width="200px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="管理类型	：">
                                {{fundEst.manType | getNameById('fundManType')}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="管理形式：">
                                {{fundEst.fundForm | getNameById('fundForm')}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="基金委派代表：" class="wordWrap">
                                {{fundEst.fundDelegate}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="基金委托管理人：" class="wordWrap">
                                {{fundEst.custodian}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="注册地：">
                                {{address}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="是否在中基协备案：">
                                {{fundEst.icc | getNameById('whether')}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" class="wordWrap">
                            <el-form-item label="中基协备案号：">
                                {{fundEst.iccNumber}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="是否在金融办备案：">
                                {{fundEst.finance | getNameById('whether')}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" class="wordWrap">
                            <el-form-item label="金融办备案号：">
                                {{fundEst.financeNumber}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="投资决策委员会：">
                                <span class="ca-font-size-14 ca-m-l-10" v-for="(i,index) in fundCommitteeList" :key="index">
                                        {{i.committeeName}}
                                    </span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="收益分配：" class="wordWrap">
                                {{fundEst.distribution}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="投资地域：" class="wordWrap">
                                {{fundEst.investmentRegion}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="投资方向：" class="wordWrap">
                                {{fundEst.investmentDirection}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="退出方式：" class="wordWrap">
                                {{fundEst.exitMode}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="投资限制：" class="wordWrap">
                                {{fundEst.restrictions}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="信息披露：" class="wordWrap">
                                {{fundEst.disclosure}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="其他：" class="wordWrap">
                                {{fundEst.other}}
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="clear"></div>
            </div>
        </div>
        <csFundDetailsBasicEdit
            v-if="isBasicEdit"
            @isEdit="isEdit"
            @saveFundBasic="saveFundBasic"
            :fundEst="fundEst"
            :committeeList="fundCommitteeList"
            @closeCommitteeItem="closeCommitteeItem"
            @changeCommitteeName="changeCommitteeName"
            @changeRegion="changeRegion"
        ></csFundDetailsBasicEdit>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import {isNoAuth} from '__service/utils';
    export default {
        data() {
            return {
                isAuthBasicEdit: isNoAuth('已投资基金-基金详情-编辑'),
                itemId: this.$route.params.fundId,
                isBasicEdit: false,
                fundEst: [],
                fundCommitteeList: [],
                initView: {
                    userEntityList: this.$store.state.user.department.userEntityList,//用户
                },
                address: '',
            }
        },
        props: {
        },
        created() {
            this.getBasicDetail();
        },
        methods: {
            getBasicDetail() {
                apiHttp(api.BASIC_DETAIL,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundEst = ret.data.fundEst;
                        this.address = this.fundEst.regionList.length > 0 ? this.fundEst.regionList[0].registrationDetailed : '';
                        this.fundCommitteeList = ret.data.fundCommitteeList;
                    }
                })
            },
            //基金基本信息点编辑
            fundBasicEdit() {
                this.isBasicEdit = true;
            },
            // 改变注册地点
            changeRegion(val) {
                this.fundEst.regionList = [];
                this.fundEst.regionList.push({
                    businessId: this.itemId,
                    businessType: val.businessType,
                    city: val.city,               // 市
                    district: val.district,       // 区
                    id: '',                       // id
                    province: val.province,       // 省
                    registrationDetailed: val.registrationDetailed,  // 详细地址
                })
            },
            //保存基本信息
            saveFundBasic(committeeList,fundEst) {
                let query = {
                    fundCommitteeList: committeeList,
                    fundEst: fundEst
                }
                apiHttp(api.DETAIL_CHANGE,query).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                            center: true
                        });
                        this.getBasicDetail();
                        this.isBasicEdit = false;
                        this.$emit('addRedDot',0)
                    }
                })
            },
            //添加投资决策委员会
            changeCommitteeName(val) {
                let flag = false;
                for (let i of this.fundCommitteeList) {
                    if (i.committeeId === val) {
                        flag = true;
                        return;
                    }
                }
                if (!flag) {
                    for (let i of this.initView.userEntityList) {
                        if (val === i.id) {
                            this.fundCommitteeList.push({committeeId: i.id,committeeName: i.userName,fundId: '',id: ''})
                        }
                    }
                }
            },
            //删除一个投资决策
            closeCommitteeItem(tag) {
                this.fundCommitteeList.splice(this.fundCommitteeList.indexOf(tag),1);
            },
            isEdit(val) {
                this.isBasicEdit = val;
                this.getBasicDetail();
            },
        },
        components: {
            'csFundDetailsBasicEdit': require('./edit.vue'),//选项卡基金信息edit页
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .wordWrap{
        word-break: break-all;
    }
</style>
